
package com.phevos.common.util;



public final class PageUtil
{

    /** Automatically generated javadoc for: TOTALNUM */
    private static final int TOTALNUM = 20;

    /**
     * ���ر�ϵͳ��ÿҳ��ʾ�ļ�¼�� ȱʡ�����Ϊ20
     */
    private static int getNumPerPage()
    {
        return TOTALNUM;
    }

    /**
     * ����ܵļ�¼������ܵ�ҳ��ÿҳ��20��
     * 
     * @param totalNum int �ܼ�¼��
     * @return int ��ҳ��
     */
    public static int getPageNum(int totalNum)
    {
        return getPageNum(totalNum, getNumPerPage());
    }

    /**
     * ����ܵļ�¼������ܵ�ҳ��ÿҳ��numPerPage��
     * 
     * @param totalNum int ����
     * @param numPerPage int ÿҳ����
     * @return int ��ҳ��
     */
    public static int getPageNum(int totalNum, int numPerPage)
    {
        if (numPerPage == 0)
            return 0;
        if (totalNum % numPerPage == 0)
        {
            return totalNum / numPerPage;
        }
        else
        {
            return (totalNum / numPerPage) + 1;
        }
    }

    /**
     * �ж��ض��ļ�¼����ÿҳ��Сָ������������ڵڼ�ҳ ��¼��Ϊ1,2,3,...
     * 
     * @param recNum int ָ���ļ�¼��
     * @param pageSize int ÿҳ�Ĵ�С
     * @return int ��¼�����ҳ��
     */
    public static int getPageIndex(int recNum, int pageSize)
    {
        if (pageSize == 0)
            return 0;
        return (recNum - 1) / pageSize + 1;
    }

    /**
     * ���ص�pageNoҳ��ݵ������¼�±�. ���pageNo<=0,�򷵻�0; ���pageSize<=0,�򷵻�0; ����ÿҳ���pageSize��;
     * ҳ��pageNo�ı��Ϊ1,2,3,... ��ݵ��±�Ϊ:1,2,3,...
     * 
     * @param pageNo ҳ��
     * @param pageSize ҳ��С
     * @return �±��1��ʼ������,����0(������Ƿ�ʱ)
     */
    public static int getStartIndexByPage(int pageNo, int pageSize)
    {
        if (pageNo <= 0 || pageSize <= 0)
        {
            return 0;
        }
        return (pageNo - 1) * pageSize + 1;
    }

    /**
     * ���ص�pageNoҳ��ݵ����һ���¼�±� ����ÿҳ���pageSize��; ҳ��pageNo�ı��Ϊ1,2,3,... ��ݵ��±�Ϊ:1,2,3,...
     * 
     * @param pageNo ҳ��
     * @param pageSize ҳ��С
     * @return 1��ʼ��һ������,����0(����Ƿ�ʱ)
     */
    public static int getEndIndexByPage(int pageNo, int pageSize)
    {
        if (pageNo <= 0 || pageSize <= 0)
        {
            return 0;
        }
        return pageNo * pageSize;
    }

    /**
     * ����ܼ�¼��,ÿҳ��¼��,������ҳ��
     * 
     * @param totalRecNum int �ܼ�¼��
     * @param perPageRecNum int ÿҳ�Ĵ�С
     * @return int ��ҳ��
     */
    public static int countPages(int totalRecNum, int perPageRecNum)
    {
        if (perPageRecNum == 0)
            return 0;
        if (totalRecNum % perPageRecNum > 0)
        {
            return totalRecNum / perPageRecNum + 1;
        }
        return totalRecNum / perPageRecNum;
    }

    /**
     * ���ҳ�뷵�ظ�ҳ�ļ�¼��
     */
  /*  private static List getListByPage(final int totalNoteNum, final int page)
    {
        List list = new ArrayList();
        int beginPage;
        int endPage;
        beginPage = totalNoteNum - (page - 1) * getNumPerPage();
        endPage = totalNoteNum - page * getNumPerPage() + 1;
        for (int i = beginPage; i >= endPage; i--)
        {
            list.add("" + i);
        }
        return list;
    }*/
}
